package net.kts.story.twitter.oauth;

import net.kts.main.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class TwitterOAuthActivity extends Activity{
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.story_oauth);
		
		WebView webView = (WebView) findViewById(R.id.webView);
		String url = getIntent().getStringExtra("URL");
		Log.d("twitter", "TwitterOAuthActivity create : " + url);
		
		webView.getSettings().setJavaScriptEnabled(true);
		webView.loadUrl(url);
		
		Button button =  (Button) findViewById(R.id.button);
		button.setOnClickListener(clickListener);
		Log.d("twitter", "TwitterOAuthActivity created : ");
	}
	
	final OnClickListener clickListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			Intent intent = getIntent();
			EditText pinText = (EditText)findViewById(R.id.pin);
			String PIN = pinText.getText().toString();
			
			if(PIN.trim().equals("")){
				Toast toast = Toast.makeText(v.getContext(), "Enter your PIN number.", 1);
				toast.show();
				return;
			}
			Log.d("twitter", "TwiterOAuthActivity PIN : "+PIN);
			intent.putExtra("PIN",PIN);
			setResult(RESULT_OK, intent);
			
			Log.d("twitter", "TwiterOAuthActivity finish ");
			finish();
		}
	};
}
